package com.zdsoft.wms;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.zdsoft.wms.feign.UserFeignClient;
import com.zdsoft.wms.interceptor.RestTemplateTokenRelay;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(clients = {UserFeignClient.class})
@ServletComponentScan("com.zdsoft.wms,filter")
public class SqdCenterApp {
    public static void main(String[] args) {
        SpringApplication.run(SqdCenterApp.class, args);
    }

    @Bean
    public IRule ribbonRule() {
        return new RandomRule();//这里配置策略，和配置文件对应 不配置不生效
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate(){

        RestTemplate restTemplate=  new RestTemplate();
        restTemplate.setInterceptors(Arrays.asList(new RestTemplateTokenRelay()));
        return  restTemplate;
    }
}
